package main.java.com.lee.atomic;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2021/12/27
 */
public class AtomicIntegerTest {
    static AtomicInteger atomicCount = new AtomicInteger(0);

    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        ExecutorService executorService = Executors.newFixedThreadPool(10);
        IntStream.rangeClosed(1, 10).forEach(i->executorService.submit(()->{
            selfPlus();
        }));
        executorService.shutdown();
        while (!executorService.isTerminated()) {

        }
        System.out.println(atomicCount.get());
        long end = System.currentTimeMillis() - start;
        System.out.println(end);
    }
    public static void selfPlus() {
        IntStream.rangeClosed(1, 10000000).forEach(i->{
            atomicCount.getAndIncrement();
        });
    }
}
